{include file="common/index_header" /}
<fieldset class="layui-elem-field layui-field-title">
   <legend>订单统计列表</legend>
</fieldset>
<div class="layui-form layui-card-header layuiadmin-card-header-auto">
   <div class="layui-form-item" >
       <div class="layui-inline">
         <label class="layui-form-label">人员选择</label>
         <div class="layui-input-block">
            <select name="person_id" lay-filter="aihao">
               <option value=""></option>
               {foreach name="person_list" item="name"}
               <option value="{$key}">{$name}</option>
               {/foreach}
            </select>
         </div>
       </div>
       <div class="layui-inline">
         <button class="layui-btn layui-btn-sm layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search" >搜索</button>
       </div>
   </div>
</div>

<div class="tile-body" style="min-height: 700px;">
   <div class="table-responsive">
      <table id="demo" lay-filter="test"></table>
      <script type="text/html" id="barDemo">
          {{# if(d.allow_refund==1 && d.status==3){ }}
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="refund">退款</a>
          {{# } }}
      </script>
   </div>
   <div class="text-center"></div>
</div> 
<hr>
{include file="common/footer" /}

<script src="/static/layui/layui.js"></script>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/jquery.form.js"></script>
<script>

var token = '{$token}';
layui.use(['table','layer','laypage','form'],function(){
    var table=layui.table;
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;

      /*$('.layui-btn.layuiadmin-btn-admin').on('click', function(){
         var type = $(this).data('type');
         active[type] ? active[type].call(this) : '';
     });*/

     // 监听搜索
     form.on('submit(LAY-user-back-search)', function(data){
         var field = data.field;
         field.token = token;
         // 执行重载
         table.reload('demo', {
            where: field
         });
     });

    table.render({
        elem: '#demo'
        ,url: "{:url('Effect/index')}?token="+token
        // ,toolbar: '#toolbarDemo'
        ,title: '用户数据表'
        // ,width: 1270
        // ,limits: [10]
        ,limit: 15
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,cols: [[
            ,{field: 'id', title: 'ID', width:80, align:'center'}
            ,{field: 'product_code', title: '商品编号', width:180, align:'center'}
            ,{field: 'title', title: '商品标题', align:'left'}
            ,{field: 'amount', title: '成交金额(元)', width:120, align:'center'}
            ,{field: 'product_count', title: '成交数量', width:120, align:'center'}
            ,{field: 'cost', title: '单件成本(元)', width:120, align:'center'}
            ,{field: 'cost_amount',title: '成本(元)', width:120, align:'center'} //toolbar: '#barDemo' align:'center'
            ,{fixed: 'right',title:'操作', width:90, align:'center', toolbar: '#barDemo'}
        ]]
        ,page:1
    });
    
    //头工具栏事件
    table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
            case 'getCheckData':
                var data = checkStatus.data;
                layer.alert(JSON.stringify(data));
                break;
            case 'getCheckLength':
                var data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
                break;
            case 'isAll':
                layer.msg(checkStatus.isAll ? '全选': '未全选');
                break;
        };
    });

     //监听行工具事件
    table.on('tool(test)', function(obj){
        var data = obj.data;
        //console.log(obj)
        if(obj.event === 'refund'){
            layer.confirm('确认退款？', function(index){
                layer.close(index);
                $.post("{:url('Order/refund')}",{order_sn:obj.data.order_sn},function(resp){
                    if (resp.code==1) {
                        // obj.del();
                        layer.msg(resp.msg, {time:2500,icon:6}, function(){
                            location.reload();
                        });
                    } else {
                        layer.msg(resp.msg, {time:2500,icon:5});
                    }
                });
            });
        }
    });

}); 
</script>